﻿//using System;
//using System.Data;
//using System.Data.SqlClient;

//public static class SqlHelper
//{
//    private static string connectionString = "YourConnectionStringHere";

//    // 执行查询并返回结果集
//    public static DataTable ExecuteQuery(string query)
//    {
//        DataTable dataTable = new DataTable();
//        using (SqlConnection connection = new SqlConnection(connectionString))
//        {
//            using (SqlCommand command = new SqlCommand(query, connection))
//            {
//                connection.Open();
//                using (SqlDataAdapter adapter = new SqlDataAdapter(command))
//                {
//                    adapter.Fill(dataTable);
//                }
//            }
//        }
//        return dataTable;
//    }

//    // 执行非查询命令（如插入、更新、删除）
//    public static int ExecuteNonQuery(string query)
//    {
//        int rowsAffected = 0;
//        using (SqlConnection connection = new SqlConnection(connectionString))
//        {
//            using (SqlCommand command = new SqlCommand(query, connection))
//            {
//                connection.Open();
//                rowsAffected = command.ExecuteNonQuery();
//            }
//        }
//        return rowsAffected;
//    }

//    // 执行查询并返回单个值
//    public static object ExecuteScalar(string query)
//    {
//        object result = null;
//        using (SqlConnection connection = new SqlConnection(connectionString))
//        {
//            using (SqlCommand command = new SqlCommand(query, connection))
//            {
//                connection.Open();
//                result = command.ExecuteScalar();
//            }
//        }
//        return result;
//    }

//    // 执行参数化查询并返回结果集
//    public static DataTable ExecuteQueryWithParameters(string query, SqlParameter[] parameters)
//    {
//        DataTable dataTable = new DataTable();
//        using (SqlConnection connection = new SqlConnection(connectionString))
//        {
//            using (SqlCommand command = new SqlCommand(query, connection))
//            {
//                command.Parameters.AddRange(parameters);
//                connection.Open();
//                using (SqlDataAdapter adapter = new SqlDataAdapter(command))
//                {
//                    adapter.Fill(dataTable);
//                }
//            }
//        }
//        return dataTable;
//    }

//    // 执行参数化非查询命令
//    public static int ExecuteNonQueryWithParameters(string query, SqlParameter[] parameters)
//    {
//        int rowsAffected = 0;
//        using (SqlConnection connection = new SqlConnection(connectionString))
//        {
//            using (SqlCommand command = new SqlCommand(query, connection))
//            {
//                command.Parameters.AddRange(parameters);
//                connection.Open();
//                rowsAffected = command.ExecuteNonQuery();
//            }
//        }
//        return rowsAffected;
//    }
//}
